<!DOCTYPE html>
<html xmlns:th="https://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>修改密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
    <style>
        .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label">现头像</label>
                <div class="layui-input-block">
                    <!-- 隐藏input 存在employeeId -->
                    <input type="hidden" name="employeeId" th:value="${session.EMPLOYEE.employeeId}">

                    <img th:src="${session.EMPLOYEE.faceImage}" width="200" height="200" style="border-radius:100%; ">

                </div>
            </div>
            <hr class="layui-bg-blue">
            <div class="layui-form-item">
                <label class="layui-form-label">上传头像</label>
                <div class="layui-input-inline">
                    <img id="faceImage" src="/static/admin/images/index/add_img.png" width="80" height="70">

                    <input type="hidden" name="faceImage" value="">

                </div>

                <div class="layui-input-inline layui-btn-container" style="width: auto;margin-top: 30px;">

                    <button type="button" class="layui-btn" id="uploadFaceButton">
                            <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>

                </div>

                <p><div class="layui-form-mid layui-word-aux" style="width: auto;">头像的尺寸限定150x150px,大小在50kb以内</div></p>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/static/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/static/admin/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.config({

    }).use(['form','upload','jquery'], function () {
        var form = layui.form,
            layer = layui.layer;
        var upload = layui.upload;
        var $ = layui.jquery;
        //上传头像
        var uploadInst = upload.render({
            elem: '#uploadFaceButton' //绑定元素
            ,url: '/admin/uploadImages' //上传接口
            ,data:{
                imgPath:'face'
            }
            ,done: function(res){
                //上传完毕回调
                layer.msg('上传成功！~~~///(^v^)\\\~~~')
                $('#faceImage').attr("src",res.data).attr("width",'200').attr("height",'200').attr("style",'border-radius:100%;');
                //把文件名赋值到隐藏input
                $("input[name='faceImage']").val(res.data);

            }
            ,error: function(){
                //请求异常回调
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            var face = data.field.faceImage;

            if (face == null || face == ""){
                layer.msg("您还没上传图片呢！")
            }else{

                $.ajax({
                    url:'/admin/updateEmployeeByEmpId',
                    type:'post',
                    data:{
                        faceImage:face,
                        employeeId:data.field.employeeId,
                        verify:1
                    },
                    success:function (res) {

                        layer.msg(res.message)

                    }

                })

            }

            return false;
        });

    });
</script>
</body>
</html>
